package com.sjziei;

import java.util.Scanner;

public class StudentService {

    private MyArray students = new MyArray(20);
    public void addStudent(){
        Student student = new Student();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号：");
        String stuNo = scanner.nextLine();
        student.setStuNo(stuNo);
        System.out.println("请输入姓名");
        String name = scanner.nextLine();
        student.setName(name);
        System.out.println("请输入年龄");
        int age = scanner.nextInt();
        student.setAge(age);
        scanner.nextLine();
        System.out.println("请输入电话：");
        String tel = scanner.nextLine();
        student.setTel(tel);
        this.students.append(student);
        //return student;

    }

    public void display(){
        for(int i=0; i<students.getLength(); i++){
            System.out.println(students.get(i));
        }
    }

    public Student findByStuNo(String stuNo) {
        for(int i=0; i<students.getLength(); i++){
            Student stu = students.get(i);
            if(stuNo.equals(stu.getStuNo())){
                return stu;
            }
        }
        return null;
    }

    public Student deleteByStuNo(String stuNo) {
        for(int i=0; i<students.getLength(); i++){
            Student stu = students.get(i);
            if(stuNo.equals(stu.getStuNo())){
                students.deleteByIndex(i);
                return stu;
            }
        }
        return null;
    }
}
